<template>
    <div class="body jobFind">
        <!-- 顶部切换 -->
        <dl class="jf_check">
            <dd>
                <li
                    :class="{ jf_liactive: topCheck == '' }"
                    @click="checkTop('')"
                >
                    <span>全部</span>
                </li>
                <li
                    :class="{ jf_liactive: topCheck == 1 }"
                    @click="checkTop(1)"
                >
                    <span>最新</span>
                </li>
                <li @click="reload()">
                    <span>重置</span>
                </li>
                <!-- <li
                    :class="{ jf_liactive: topCheck == 2 }"
                    @click="checkTop(2)"
                >
                    <span>附近</span>
                </li> -->
            </dd>
            <dd>
                <li @click="isCheckCity = !isCheckCity">
                    <span>{{ localText }}</span
                    ><img
                        src="../../assets/newimg/jobHome/bendi_icon_sx.png"
                        alt=""
                    />
                </li>
                <li @click="idCheckOther = !idCheckOther">
                    <span>筛选</span
                    ><img
                        src="../../assets/newimg/jobHome/bendi_icon_sx.png"
                        alt=""
                    />
                </li>
            </dd>
        </dl>
        <!-- 列表 -->
        <div class="j_gxzw">
            <div v-if="pageListInfo.jobs_list.list.length > 0">
                <a
                    class="j_gx_li"
                    v-for="(item, index) in pageListInfo.jobs_list.list"
                    :key="index"
                    @click="
                        $router.push({
                            path: '/jobFindDetail',
                            query: { id: item.id },
                        })
                    "
                >
                    <h1>
                        <span>{{ item.jobs_name }}</span>
                        <i>{{ item.wage_cn }}</i>
                    </h1>
                    <h2>
                        {{ item.companyname
                        }}<i style="float: right">{{ item.refreshtime }}</i>
                    </h2>
                    <h3>
                        <span v-for="(li, i) in item.tag_cn" :key="i">{{
                            li
                        }}</span>
                    </h3>
                    <h4>
                        <span>
                            <img
                                src="../../assets/newimg/index/home_icon_huo@2x.png"
                                alt=""
                            />
                            <b>{{ item.contact.contact }}</b>
                        </span>
                        <i>{{ item.district_cn }}</i>
                    </h4>
                </a>
            </div>
        </div>
        <!-- 缺省页面 -->
        <component
            :is="'ContentNone'"
            :isgoShop="false"
            v-show="
                pageListInfo.jobs_list.list.length == 0 && pageInfo.pageSatus
            "
        ></component>
        <!-- 地址选择组件 -->
        <component
            :is="'Addres'"
            v-if="isCheckCity"
            @checkAddresData="checkAddresfn"
            @closeAddresProps="closeAddresPropsfn"
        ></component>
        <!-- 弹窗一 -->
        <van-popup v-model="idCheckOther" round closeable>
            <div class="ed_props_box1">
                <h1>筛选</h1>
                <div
                    class="ed_li"
                    v-for="(item, index) in checkInfo"
                    :key="index"
                >
                    <h2>{{ item.name }}</h2>
                    <div>
                        <ul>
                            <li
                                v-for="(el, i) in item.children"
                                :key="i"
                                :class="{
                                    checkActive: item.checkName == el,
                                }"
                                @click="
                                    (item.checkName = el), (item.checkId = i)
                                "
                            >
                                {{ el }}
                            </li>
                        </ul>
                    </div>
                </div>

                <div class="smalBtn smalBtn_class" @click="submitTrue">
                    <span>确认</span>
                </div>

                <h4>个人信息将会严格按照监管要求加密保存</h4>
            </div>
        </van-popup>

        <!-- 分页 -->
        <component
            :is="'Pagination'"
            :pageInfo="pageInfo"
            @pageNext="pageNext"
            @changePageStatus="changePageStatus"
        ></component>
        <div class="zhanwei"></div>
    </div>
</template>

<script>
import { axiosPost } from '../../axios';
import { Toast } from 'vant';
import { mapState } from 'vuex';
export default {
    name: '',
    computed: {
        ...mapState({
            searchVal: (state) => state.searchVal,
            searchStatus: (state) => state.searchStatus,
        }),
    },
    data() {
        return {
            // 顶部切换类型
            topCheck: '',
            // 区域文本
            localText: '区域',
            // 地址选择弹窗
            isCheckCity: false,
            // 其他选择弹窗
            idCheckOther: false,
            checkInfo: [],
            checkOverInfo: [],

            pageListInfo: {
                jobs_list: {
                    list: [],
                },
            },
            // 分页组件信息
            pageInfo: {
                pagingText: '',
                pageNum: 1,
                pageSatus: true,
            },
        };
    },
    watch: {
        // 监听搜索按钮点击
        searchStatus(val) {
            if (val.split('%')[0] == 'false' || this.searchVal) {
                this.pageListInfo.jobs_list.list = [];
                this.pageInfo.pageSatus = false;
                this.getList(); // 根据type获取订单
            }
        },
    },
    mounted() {
        this.getList();
    },
    methods: {
        reload() {
            window.location.reload();
        },
        // 顶部切换事件
        checkTop(type) {
            this.topCheck = type;
            this.checkOverInfo['is_new'] = type;

            this.pageListInfo.jobs_list.list = [];
            this.pageInfo.pageSatus = false;
            this.getList(); // 根据type获取订单
        },
        // 关闭地址选择
        closeAddresPropsfn(data) {
            this.ischeckCity = data;
        },
        // 地址选择回调
        checkAddresfn(selectedOptions) {
            this.localText = selectedOptions[2].text;
            this.checkOverInfo['citycategory'] = selectedOptions[2].value;

            this.pageListInfo.jobs_list.list = [];
            this.pageInfo.pageSatus = false;
            this.getList(); // 根据type获取订单
        },
        // 分页组件修改状态
        changePageStatus(data) {
            this.pageInfo.pageSatus = data;
        },
        // 分页组件回调
        pageNext(data) {
            this.pageInfo.pageNum = data;
            this.getList(data); // 根据type获取订单
        },
        // 提交筛选
        submitTrue() {
            this.computerCheck();

            this.pageListInfo.jobs_list.list = [];
            this.pageInfo.pageSatus = false;
            this.getList(); // 根据type获取订单
        },
        // 计算选中的选项
        computerCheck() {
            this.checkInfo.forEach((el) => {
                if (el.checkName != '不限') {
                    this.checkOverInfo[el.id] =
                        el.checkId == 0 ? '' : el.checkId;
                }
            });
            this.idCheckOther = false;
        },
        // 获取评价订单列表
        getList(page = 1, page_size = 10) {
            axiosPost(
                '/apis/jobs/index',
                {
                    page: page,
                    page_size: page_size,
                    is_new: this.checkOverInfo['is_new'],
                    citycategory: this.checkOverInfo['citycategory'],
                    education_list: this.checkOverInfo['education_list'],
                    experience_list: this.checkOverInfo['experience_list'],
                    nature_list: this.checkOverInfo['nature_list'],
                    tag_list: this.checkOverInfo['tag_list'],
                    update_list: this.checkOverInfo['update_list'],
                    wage_list: this.checkOverInfo['wage_list'],
                    trade_list: this.checkOverInfo['trade_list'],
                    key: this.searchVal,
                },
                (res) => {
                    // console.log(res);
                    if (res.status != 1) {
                        return Toast({
                            message: res.msg,
                            duration: 2000,
                        });
                    }

                    // 判断是否为第一次加载
                    if (!this.pageListInfo.filter_list) {
                        this.pageListInfo.filter_list = res.data.filter_list;

                        // 整理选项数据
                        this.checkInfo = [];
                        for (let i in res.data.filter_list) {
                            if (typeof res.data.filter_list[i] == 'boolean') {
                                continue;
                            }
                            let name = '';
                            switch (i) {
                                case 'education_list':
                                    name = '学历要求';
                                    break;
                                case 'experience_list':
                                    name = '工作经验';
                                    break;
                                case 'nature_list':
                                    name = '工作性质';
                                    break;
                                case 'tag_list':
                                    name = '福利待遇';
                                    break;
                                case 'update_list':
                                    name = '更新时间';
                                    break;
                                case 'wage_list':
                                    name = '工资';
                                    break;
                                case 'trade_list':
                                    name = '职位';
                                    break;
                                default:
                                    break;
                            }
                            res.data.filter_list[i][0] = '不限';
                            let params = {
                                id: i,
                                name: name,
                                checkId: '',
                                checkName: '不限',
                                children: res.data.filter_list[i],
                            };
                            this.checkInfo.push(params);
                        }
                    }

                    // 分页处理
                    if (
                        res.data.jobs_list.page_params.nowPage ==
                        res.data.jobs_list.page_params.totalPages
                    ) {
                        this.pageInfo.pagingText = '没有更多啦！';
                    } else {
                        this.pageInfo.pagingText = '商品加载中...';
                    }
                    this.pageInfo.pageSatus = true;

                    // 数据处理
                    res.data.jobs_list.list.forEach((element) => {
                        this.pageListInfo.jobs_list.list.push(element);
                    });

                    this.pageListInfo.jobs_list.page_params =
                        res.data.jobs_list.page_params;
                }
            );
        },
    },
};
</script>

<style lang="less" scope>
.jobFind {
    .jf_check {
        height: 2.0267rem;

        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 0.4267rem;

        dd,
        dt {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .jf_liactive {
            background: #fff1f1;
            color: #ff3b3b;
        }

        li {
            font-size: 0.64rem;
            font-weight: 400;
            color: #000000;
            display: flex;
            justify-content: space-between;
            align-items: center;
            height: 0.8533rem;
            border-radius: 0.4267rem;
            padding: 0 0.4267rem;

            img {
                width: 0.256rem;
                margin-left: 0.1707rem;
            }
        }
    }

    // 弹窗一
    .ed_props_box1 {
        width: 15.1467rem;
        max-height: 18.88rem;
        background: #ffffff;
        border-radius: 0.4267rem;

        h1 {
            font-size: 0.8107rem;
            font-weight: 500;
            color: #000000;
            text-align: center;
            margin: 0.896rem auto 0;
        }

        .ed_li {
            margin: 0.5973rem 0.7467rem 0;
            border-bottom: 1px solid #d2d3d5;
            padding-bottom: 0.54rem;

            h2 {
                font-size: 0.5973rem;
                font-weight: 400;
                color: #000000;
                line-height: 0.64rem;
            }

            ul {
                overflow: hidden;

                .checkActive {
                    background: #fff1f1;
                    border: 1px solid #fd7779;
                    color: #fd7779;
                }

                li {
                    height: 1.5787rem;
                    margin-top: 0.4267rem;
                    border: 1px solid #d2d3d5;
                    border-radius: 0.7893rem;
                    text-align: center;
                    line-height: 1.5787rem;
                    font-size: 0.5973rem;
                    font-weight: 400;
                    color: #888888;
                    padding: 0 0.7253rem;
                    margin-right: 0.2773rem;
                    white-space: nowrap;
                    float: left;
                }
            }
        }

        h4 {
            font-size: 0.5547rem;
            font-weight: 400;
            color: #b8b8b8;
            line-height: 0.64rem;
            text-align: center;
            padding-bottom: 1rem;
        }
    }

    .smalBtn_class {
        background: #fe333d !important;
    }

    .smalBtn {
        width: 8.4267rem;
        height: 1.92rem;
        background: #ffd8d8;
        border-radius: 0.96rem;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 0.7253rem;
        font-weight: 400;
        margin: 1.4507rem auto 0.64rem;
        color: #ffffff;
    }

    .van-popup__close-icon {
        font-size: 1rem;
        top: 0.7rem;
        right: 0.5rem;
    }
}
</style>
